package cn.kent.heima.base.methodArea;

/**
 * 演示 StringTable 垃圾回收
 * -Xmx10m -XX:+PrintStringTableStatistics -XX:+PrintGCDetails -verbose:gc
 */
@SuppressWarnings("all")
public class Demo_11 {
    public static void main(String[] args) {
        int i = 0;
        try {
            for (int j = 0; j < 7000; j++) { // 4000 -> 5691 7000->1794  我的计算机在5000左右会触发gc, 使得 StringTable statistics: 下降
                String.valueOf(i).intern();
                i++;
            }
        } catch (Throwable throwable) {
            throwable.printStackTrace();
        }finally {
            System.out.println(i);
        }
    }
}
